package com.ruoyi.cs.event.supplieroffer.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.cs.event.supplieroffer.domain.SupplierOffer;
import com.ruoyi.cs.event.supplieroffer.service.ISupplierOfferService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 供应商报价
 * @author Drj 2021/6/28
 */
@RestController
@RequestMapping("/cs/supplieroffer")
@Api(value = "供应商报价模块", tags = "供应商报价接口")
public class SupplierOfferController extends BaseController {
    @Autowired
    private ISupplierOfferService supplierOfferService;

    /**
     * 获取供应商报价
     * @param supplierOffer
     * @return
     */
    @ApiOperationSupport(includeParameters = {"SupplierInfo.supplierInfoId", "SupplierInfo.supplierQuotaId", "SupplierInfo.offerTime"})
    @ApiOperation(value = "获取供应商报价列表",notes = "查询所有供应商报价")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody SupplierOffer supplierOffer) {
        startPage();

        List<SupplierOffer> supplierOffers = supplierOfferService.selectSupplierOfferList(supplierOffer);
        return getDataTable(supplierOffers);
    }

    /**
     * 导出供应商报价
     *
     * @param supplierOffer
     * @return
     */
    @PostMapping("/export")
    public AjaxResult export(@RequestBody SupplierOffer supplierOffer) {
        List<SupplierOffer> List = supplierOfferService.selectSupplierOfferList(supplierOffer);
        ExcelUtil<SupplierOffer> util = new ExcelUtil<SupplierOffer>(SupplierOffer.class);
        return util.exportExcel(List, "供应商报价单数据");
    }

    /**
     * 新增供应商报价
     * @param supplierOffer 供应商报价单据
     * @return
     */
    @ApiOperation(value = "新增供应商报价", notes = "新增供应商报价")
    @ApiImplicitParam(name = "supplierOffer", value = "新增供应商报价", dataType = "SupplierOffer")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SupplierOffer supplierOffer) {
        try {
            return toAjax(supplierOfferService.insertSupplierOffer(supplierOffer));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("新增失败");
        }
    }

    /**
     * 更新供应商报价
     * @param supplierOffer 供应商报价单据
     * @return
     */
    @ApiOperation(value = "更新供应商报价", notes = "更新供应商报价")
    @ApiImplicitParam(name = "supplierOffer", value = "更新供应商报价", dataType = "SupplierOffer")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody SupplierOffer supplierOffer) {
        try {
            return toAjax(supplierOfferService.updateSupplierOffer(supplierOffer));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("修改失败");
        }
    }

    /**
     * 删除供应商报价
     * 仅修改删除标志位
     *
     * @param supplierOffer 供应商报价单据
     * @return
     */
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody SupplierOffer supplierOffer) {
        return toAjax(supplierOfferService.updateSupplierOfferDeleteFlag(supplierOffer));
    }

}
